import React from "react";
import { Tag } from "antd";
import { ProColumns } from "@ant-design/pro-components";
import { loadStatics, taskPageSearch } from "./service";

const baseColumns: ProColumns[] = [
    {
        title: '流程名称',
        dataIndex: 'processName',
    },
    {
        title: '节点名称',
        dataIndex: 'nodeName',
    },
    {
        title: '开始时间',
        dataIndex: 'startTime',
    }
];

const doneColumns: ProColumns[] = [
    {
        title: '结束时间',
        dataIndex: 'endTime',
    },
    {
        title: '流程状态',
        dataIndex: 'status',
        align: 'center',
        render: (dom, entity, index) => {
              if (entity.status === 1) {
                  return React.createElement(Tag, { color: 'success' }, '已完成');
              } else if (entity.status === 2) {
                  return React.createElement(Tag, { color: 'red' }, '已作废');
              } else {
                  return React.createElement(Tag, { color: 'processing' }, '进行中');
              }
        },
    },
];

export const loadCount = async () => {
    const { success, result } = await loadStatics();
    if (success) {
        return result;
    }
    return false;
}

export const loadTableData = async (params: any) => {
    const { success, result } = await taskPageSearch({ ...params });
    return {
        success,
        total: result.total || 0,
        data: result.records || []
    }
}

export const items = [
    {
        key: 'todo',
        title: '待办',
        status: 'processing',
        value: 10,
        columns: baseColumns,
        total: true
    },
    {
        key: 'done',
        title: '已办',
        status: 'success', value: 5,
        columns: baseColumns.concat(doneColumns),
        total: true
    },
    {
        key: 'meTodo',
        title: '我的待办',
        status: 'default',
        value: 1,
        columns: baseColumns,
    },
    {
        key: 'meDone',
        title: '我的已办',
        status: 'default',
        value: 1,
        columns: baseColumns.concat(doneColumns),
    },
];